//
//  GraphicDetailsViewController.m
//  PeopleStreet
//
//  Created by 辰领科技 on 16/10/28.
//  Copyright © 2016年 yuf. All rights reserved.
//

#import "GraphicDetailsViewController.h"
#import "GraphicDetailsCollectionViewCell.h"

static NSString * identifierOne = @"cellOne";
static NSString * identifierTwo = @"cellTwo";

@interface GraphicDetailsViewController ()
<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UIView *navView;
@property (weak, nonatomic) IBOutlet UICollectionView *collectionView;

@end

@implementation GraphicDetailsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initViewLayout];
}
- (void)initViewLayout{
    [self adaptiveViewLayout:self.view];
    [self adaptiveViewLayout:self.navView];
    
    UICollectionViewFlowLayout *flowLayout =[[UICollectionViewFlowLayout alloc]init];
    flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
    flowLayout.minimumInteritemSpacing = 0;
    flowLayout.minimumLineSpacing = 0;
    self.collectionView.backgroundColor = [UIColor clearColor];
    self.collectionView.collectionViewLayout = flowLayout;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    
}

- (IBAction)back:(id)sender {
    [self.navigationController  popViewControllerAnimated:YES];
}
#pragma mark - 分享
- (IBAction)share:(id)sender {
}

#pragma mark - 收藏
- (IBAction)collection:(id)sender {
}

#pragma mark -- UICollectionViewDataSource
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 8;
}
//定义展示的Section的个数
-(NSInteger)nmumberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}

//定义每个UICollectionView 的大小
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(158*VerticalRatio(), 150*VerticalRatio());
    
}
//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(0,0, 0, 0);
}
//每个UICollectionView展示的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    NSInteger hang;
    BOOL cross = YES;//偶数行&&奇数行
    if (indexPath.row%2 == 0) {
        hang = indexPath.row/2;
        if (hang%2 == 0) {
            cross = NO;//偶数行
        } else if (hang%2 != 0) {
            cross = YES;//奇数列
        }
    } else if (indexPath.row%2 != 0) {
        hang = (indexPath.row+1)/2;
        if (hang%2 == 0) {
            cross = NO;//偶数行
        } else if (hang%2 != 0) {
            cross = YES;//奇数列
        }
    }
    if (indexPath.row%2 == 0) {
        //第二列
        if (cross == YES) {
            //奇数行
            GraphicDetailsCollectionViewCell * Cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifierTwo forIndexPath:indexPath];
            return Cell;
        } else if (cross == NO) {
            //偶数行
            GraphicDetailsCollectionViewCell * Cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifierOne forIndexPath:indexPath];
            return Cell;
        }
    } else if (indexPath.row%2 != 0) {
        //第一列
        if (cross == YES) {
            //奇数行
            GraphicDetailsCollectionViewCell * Cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifierTwo forIndexPath:indexPath];
            return Cell;
        } else if (cross == NO) {
            //偶数行
            GraphicDetailsCollectionViewCell * Cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifierOne forIndexPath:indexPath];
            return Cell;
        }
    }
    
    
        return nil;
}
    
    


@end
